home *** CD-ROM | disk | FTP | other *** search
- package
- {
- import flash.utils.*;
- import flash.xml.XMLDocument;
- import flash.xml.XMLNode;
- import flash.xml.XMLNodeType;
-
- public class DressupLevelInfo
- {
-
-
- protected var _aAllowedClothes:Array;
-
- public var LevelCutscene:String;
-
- public var PowerUps:Array;
-
- public var UniqueThemes:Array;
-
- public var FiguresLeft:int = 10;
-
- public var LevelMusic:String;
-
- public var Package:PartTemplatePackage;
-
- public var LevelName:String;
-
- public var MillisecondsAllowed:Number = 95000;
-
- public var StartTime:int;
-
- public var LevelBackground:String;
-
- protected var _aPartners:Array;
-
- public var CurrentScore:int = 0;
-
- public var LevelPoseMultiplier:Number;
-
- public var DoubleDamage:Boolean = false;
-
- public var TotalFigures:int = 10;
-
- public var LevelTime:int;
-
- public var Partners:Array;
-
- public var PowerupRequiredScore:int = 2000;
-
- public var AvailablePowerups:Array;
-
- public var UsedItems:Array;
-
- public var CurrentTotalLetterGrade:int = 0;
-
- public var Themes:Array;
-
- public var bEndLevel:Boolean;
-
- public var TotalAccessories:int = 0;
-
- public var NumModels:int = 3;
-
- public var DoubleDamageTarget:String = null;
-
- public var LevelMinScore:int;
-
- protected var _aThemeLineup:Array;
-
- public var ModelLineup:Array;
-
- public var RemainingAccessories:Array;
-
- public var LevelPoses:Array;
-
- public var TopModels:Array;
-
- public function DressupLevelInfo(param1:String)
- {
- var _loc2_:DressupTheme = null;
- var _loc3_:Database = null;
- var _loc4_:XMLDocument = null;
- var _loc5_:XMLNode = null;
- var _loc6_:XMLNode = null;
- var _loc7_:XMLNode = null;
- var _loc8_:XMLNode = null;
- var _loc9_:String = null;
- var _loc10_:DressupTheme = null;
- var _loc11_:XMLNode = null;
- var _loc12_:XMLNode = null;
- var _loc13_:XMLNode = null;
- var _loc14_:Class = null;
- var _loc15_:* = undefined;
- var _loc16_:DressupTheme = null;
- var _loc17_:Array = null;
- var _loc18_:String = null;
- var _loc19_:PartTemplate = null;
- var _loc20_:String = null;
- var _loc21_:Boolean = false;
- var _loc22_:String = null;
- var _loc23_:Array = null;
- var _loc24_:int = 0;
- var _loc25_:int = 0;
- var _loc26_:DressupTheme = null;
- var _loc27_:DressupTheme = null;
- Themes = new Array();
- UniqueThemes = new Array();
- CurrentScore = 0;
- CurrentTotalLetterGrade = 0;
- FiguresLeft = 10;
- TotalFigures = 10;
- TotalAccessories = 0;
- RemainingAccessories = new Array();
- PowerUps = new Array();
- AvailablePowerups = new Array();
- Partners = new Array();
- PowerupRequiredScore = 2000;
- NumModels = 3;
- LevelPoses = new Array();
- MillisecondsAllowed = 95 * 1000;
- DoubleDamage = false;
- DoubleDamageTarget = null;
- _aAllowedClothes = new Array();
- _aThemeLineup = new Array();
- _aPartners = new Array();
- UsedItems = new Array();
- TopModels = new Array();
- ModelLineup = new Array();
- super();
- trace("Starting level : " + param1);
- if(param1 == "Tutorial")
- {
- NumModels = 1;
- }
- _loc3_ = new Database();
- Package = new PartTemplatePackage();
- Package.copy(MainDocument.Package);
- LevelName = param1;
- _loc4_ = MainDocument.Levels.getDoc();
- for each(_loc5_ in _loc4_.firstChild.childNodes)
- {
- if(_loc5_.nodeType == XMLNodeType.ELEMENT_NODE)
- {
- if(_loc5_.attributes["name"] == param1)
- {
- FiguresLeft = parseInt(_loc5_.attributes["rounds"].toString());
- TotalFigures = FiguresLeft;
- LevelBackground = _loc5_.attributes["background"];
- if(_loc5_.attributes["score"] != undefined)
- {
- LevelMinScore = parseInt(_loc5_.attributes["score"].toString());
- }
- else
- {
- LevelMinScore = 40000;
- }
- if(_loc5_.attributes["cutscene"] != undefined)
- {
- LevelCutscene = _loc5_.attributes["cutscene"];
- }
- else
- {
- LevelCutscene = "";
- }
- if(_loc5_.attributes["final"] != undefined)
- {
- bEndLevel = true;
- }
- else
- {
- bEndLevel = false;
- }
- if(_loc5_.attributes["music"] != undefined)
- {
- LevelMusic = _loc5_.attributes["music"];
- }
- else
- {
- LevelMusic = "MenuMusic";
- }
- for each(_loc6_ in _loc5_.childNodes)
- {
- if(_loc6_.nodeType == XMLNodeType.ELEMENT_NODE)
- {
- if(_loc6_.localName == "Clothes")
- {
- for each(_loc7_ in _loc6_.childNodes)
- {
- if(_loc7_.nodeType == XMLNodeType.ELEMENT_NODE)
- {
- _aAllowedClothes.push(_loc7_.attributes["name"]);
- }
- }
- }
- else if(_loc6_.localName == "Occasions")
- {
- for each(_loc8_ in _loc6_.childNodes)
- {
- if(_loc8_.nodeType == XMLNodeType.ELEMENT_NODE)
- {
- _loc9_ = String(_loc8_.attributes["name"]);
- _loc10_ = _loc3_.getTheme(_loc9_).clone();
- if(_loc8_.attributes["partner"] != undefined)
- {
- _loc10_.ThemePartner = _loc3_.getPartner(_loc8_.attributes["partner"].toString());
- }
- Themes.push(_loc10_);
- }
- }
- }
- else if(_loc6_.localName == "Partners")
- {
- for each(_loc11_ in _loc6_.childNodes)
- {
- if(_loc11_.nodeType == XMLNodeType.ELEMENT_NODE)
- {
- _aPartners.push(_loc3_.getPartner(_loc11_.attributes["name"]));
- }
- }
- }
- else if(_loc6_.localName == "AvailablePowerups")
- {
- for each(_loc12_ in _loc6_.childNodes)
- {
- if(_loc12_.nodeType == XMLNodeType.ELEMENT_NODE)
- {
- AvailablePowerups.push(_loc12_.attributes["name"]);
- }
- }
- }
- else if(_loc6_.localName == "InitialPowerups")
- {
- for each(_loc13_ in _loc6_.childNodes)
- {
- if(_loc13_.nodeType == XMLNodeType.ELEMENT_NODE)
- {
- _loc15_ = new (_loc14_ = Class(getDefinitionByName(_loc13_.attributes["name"])))();
- addPowerup(_loc15_);
- }
- }
- }
- }
- }
- }
- }
- }
- if(_aAllowedClothes.length > 0)
- {
- for each(_loc16_ in Themes)
- {
- for each(_loc20_ in _loc16_.SampleParts)
- {
- _loc21_ = false;
- for each(_loc22_ in _aAllowedClothes)
- {
- if(_loc22_ == _loc20_)
- {
- _loc21_ = true;
- break;
- }
- }
- if(!_loc21_)
- {
- _aAllowedClothes.push(_loc20_);
- }
- }
- }
- _loc17_ = new Array();
- for each(_loc18_ in _aAllowedClothes)
- {
- if(_loc18_.indexOf("_VER2") < 0)
- {
- _loc17_.push(_loc18_);
- }
- }
- Package.filter(_loc17_);
- for each(_loc19_ in Package.Templates)
- {
- if(_loc19_.Category == "accessory")
- {
- RemainingAccessories.push(_loc19_);
- }
- }
- shuffleArray(RemainingAccessories);
- TotalAccessories = RemainingAccessories.length;
- }
- UniqueThemes = Themes;
- if(_aPartners.length > 0)
- {
- _loc23_ = new Array();
- _loc24_ = 0;
- while(_loc24_ < _aPartners.length)
- {
- _loc25_ = 0;
- while(_loc25_ < Themes.length)
- {
- _loc26_ = new DressupTheme();
- (_loc26_ = (_loc27_ = Themes[_loc25_] as DressupTheme).clone()).ThemePartner = _aPartners[_loc24_] as Partner;
- _loc23_.push(_loc26_);
- _loc25_++;
- }
- _loc24_++;
- }
- Themes = _loc23_;
- }
- _aThemeLineup = createSelection(Themes,FiguresLeft);
- shuffleArray(_aThemeLineup);
- PowerupRequiredScore = 500;
- TopModels.push(new TopModel());
- TopModels.push(new TopModel());
- TopModels.push(new TopModel());
- TopModels.push(new TopModel());
- setupModelLineup();
- }
-
- public static function createSelection(param1:Array, param2:int) : Array
- {
- var _loc3_:Array = null;
- _loc3_ = expandArray(param1,param2);
- shuffleArray(_loc3_);
- return _loc3_;
- }
-
- public static function shuffleArray(param1:Array) : void
- {
- var _loc2_:Object = null;
- var _loc3_:int = 0;
- var _loc4_:int = 0;
- _loc3_ = 0;
- while(_loc3_ < param1.length)
- {
- _loc4_ = Math.random() * param1.length;
- _loc2_ = param1[_loc3_];
- param1[_loc3_] = param1[_loc4_];
- param1[_loc4_] = _loc2_;
- _loc3_++;
- }
- }
-
- public static function expandArray(param1:Array, param2:int) : Array
- {
- var _loc3_:int = 0;
- var _loc4_:Array = null;
- _loc4_ = new Array();
- _loc3_ = 0;
- while(_loc3_ < param2)
- {
- _loc4_.push(param1[_loc3_ % param1.length]);
- _loc3_++;
- }
- return _loc4_;
- }
-
- public function updatePowerups() : void
- {
- var _loc1_:Array = null;
- var _loc2_:Powerup = null;
- _loc1_ = new Array();
- for each(_loc2_ in PowerUps)
- {
- if(_loc2_.Charges > 0)
- {
- _loc1_.push(_loc2_);
- }
- }
- PowerUps = _loc1_;
- }
-
- protected function addPowerup(param1:Powerup) : Boolean
- {
- var _loc2_:Boolean = false;
- _loc2_ = false;
- updatePowerups();
- if(PowerUps.length < 5)
- {
- _loc2_ = true;
- param1.init(this);
- PowerUps.push(param1);
- }
- return _loc2_;
- }
-
- public function getRandomTheme() : DressupTheme
- {
- var _loc1_:int = 0;
- var _loc2_:DressupTheme = null;
- if(_aThemeLineup.length > 0)
- {
- return _aThemeLineup.pop() as DressupTheme;
- }
- _loc1_ = Math.random() * Themes.length;
- _loc2_ = Themes[_loc1_];
- _loc1_ = Math.random() * _aPartners.length;
- if(_aPartners.length > 0)
- {
- _loc2_.ThemePartner = _aPartners[_loc1_];
- }
- return _loc2_;
- }
-
- public function getNextAccessories() : Array
- {
- var _loc1_:PartTemplate = null;
- var _loc2_:Array = null;
- trace("Total = " + TotalAccessories + " FiguresLeft = " + FiguresLeft + " Remaining = " + RemainingAccessories.length);
- for each(_loc1_ in RemainingAccessories)
- {
- trace(" " + _loc1_.Name);
- }
- _loc2_ = new Array();
- if(FiguresLeft > 0 && RemainingAccessories.length > 0)
- {
- if(TotalAccessories <= TotalFigures / FiguresLeft * RemainingAccessories.length)
- {
- _loc2_.push(RemainingAccessories.pop());
- }
- }
- trace("Return = " + _loc2_.length);
- return _loc2_;
- }
-
- public function getLevelPartners() : Array
- {
- return _aPartners;
- }
-
- public function awardPowerup(param1:int) : Powerup
- {
- var _loc2_:Powerup = null;
- var _loc3_:int = 0;
- var _loc4_:Class = null;
- _loc2_ = null;
- if(AvailablePowerups.length == 0)
- {
- return null;
- }
- if(param1 > PowerupRequiredScore && AvailablePowerups.length > 0)
- {
- _loc3_ = Math.random() * AvailablePowerups.length;
- _loc2_ = new (_loc4_ = Class(getDefinitionByName(AvailablePowerups[_loc3_])))();
- if(!addPowerup(_loc2_))
- {
- _loc2_ = null;
- }
- }
- return _loc2_;
- }
-
- public function getNextModel() : PartTemplate
- {
- if(ModelLineup.length > 0)
- {
- return ModelLineup.pop() as PartTemplate;
- }
- return null;
- }
-
- public function getRankDiamonds() : int
- {
- if(CurrentScore > 10000)
- {
- return 5;
- }
- if(CurrentScore > 4000)
- {
- return 4;
- }
- if(CurrentScore > 2000)
- {
- return 3;
- }
- if(CurrentScore > 1000)
- {
- return 2;
- }
- if(CurrentScore > 500)
- {
- return 1;
- }
- return 0;
- }
-
- internal function setupModelLineup() : void
- {
- var _loc1_:Array = null;
- var _loc2_:int = 0;
- var _loc3_:int = 0;
- ModelLineup = new Array();
- _loc1_ = MainDocument.Package.getAllTemplates("body");
- _loc2_ = FiguresLeft;
- _loc3_ = 0;
- while(_loc2_ > 0)
- {
- ModelLineup.push(_loc1_[_loc3_]);
- _loc3_++;
- if(_loc3_ >= _loc1_.length)
- {
- _loc3_ = 0;
- }
- _loc2_--;
- }
- shuffleArray(ModelLineup);
- }
- }
- }
-